package JdbcTemplate.operation.query;

import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.core.RowMapper;
import java.sql.ResultSet;
import java.sql.SQLException;

/*
实现RowMapper接口获取结果集,也可以通过匿名内部类获取结果集(不需要另外实现RowMapper接口)
 */
@Configuration
public class PersonMapper implements RowMapper {

    @Override
    public Object mapRow(ResultSet resultSet, int i) throws SQLException {
        Person person=new Person();
        /*
        获取结果集放进实体类对象中
         */
        person.setId_identity(resultSet.getInt("id_identity"));
        person.setUsername(resultSet.getString("username"));
        person.setPassword(resultSet.getString("password"));
        person.setFirst_name(resultSet.getString("first_name"));
        person.setLast_name(resultSet.getString("last_name"));
        person.setEmail(resultSet.getString("email"));
        System.out.println(person.getUsername());
        System.out.println(person.getUsername()+person.getEmail()+person.getFirst_name()+
                person.getLast_name()+person.getPassword() +person.getId_identity());
        return person;
    }
}
